import { RouterProvider } from 'react-router-dom';

import { ConfigProvider } from 'antd';
import zhCN from 'antd/locale/zh_CN';
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';

import AntdContextHolder from '@/plugins/AntdContextHolder';

import { antdTheme } from './config/theme';
import router from './router';

// 设置 dayjs 为中文
dayjs.locale('zh-cn');

function App() {
  useEffect(() => {
    function randomUUID() {
      return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        const r = (Math.random() * 16) | 0;
        return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
      });
    }
    if (typeof crypto !== 'undefined' && !crypto.randomUUID) {
      crypto.randomUUID = randomUUID;
    }
  }, []);
  return (
    <ConfigProvider locale={zhCN} theme={antdTheme}>
      <AntdContextHolder>
        <GlobalLoading />
        <RouterProvider router={router} />
      </AntdContextHolder>
    </ConfigProvider>
  );
}

export default App;
